﻿using System;

namespace FinMkts.Prices.ClientService
{
    /// <summary>
    /// A subscription to a topic that is notified when that data is published on the topic
    /// </summary>
    internal class Subscription : IEquatable<Subscription>
    {
        public string Topic { get; private set; }
        public INotification Channel { get; private set; }

        public Subscription(string topic, INotification channel)
        {
            if (topic == null) throw new ArgumentNullException("topic");
            Topic = topic;
            Channel = channel;
        }

        public bool Equals(Subscription other)
        {
            if (((object)other) == null) return false;
            return Topic.Equals(other.Topic);
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Subscription);
        }

        public override int GetHashCode()
        {
            return Topic.GetHashCode();
        }

        public static bool operator ==(Subscription left, Subscription right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Subscription left, Subscription right)
        {
            return !Equals(left, right);
        }
    }
}